import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, DelDataButton, AnnexButton } from '../Common/options'

export const SecurityDetailAttachment = async ({ twoData, actionRef, Permission, OptionsEvent }) => {
    let dataList = {
        type: '整改附件列表',
        width: 800,
        classification: 'SelectModal',
        hideInSelect: true,
        hideInSearch: true,
        pageSize: 10,
        params: { pageIndex: 1, securityDetailUuid: twoData.uuid },
        initialValues: { securityDetailUuid: twoData.uuid },
        get: API_LIST()['getSecurityDetailAttachment'],
        added: 'posSecurityDetailAttachment',
        options: [
            twoData.handling === 1 &&
                Permission.findIndex(v => v.uuid === 'bcbc660a-cfa9-43cb-b3ba-048514d30c48') !== -1 && (
                    <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增整改附件" />
                ),
        ],
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'securityDetailUuid',
                title: 'securityDetailUuid',
                valueType: 'hidden',
                hideInTable: true,
            },
            {
                dataIndex: 'originalName',
                title: '附件名称',
                valueType: 'input',
                rules: true,
                ellipsis: true,
                width: 400,
                hideInSearch: true,
                hideInModify: true,
                hideInAdded: true,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '文件附件',
                valueType: 'upload',
                valueFile: [1],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '文件附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { fileUrl, uuid } = record
                    return [
                        fileUrl && <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="查看附件" />,
                        twoData.handling === 1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="SecurityDetailAttachmentNew"
                                uuid={[twoData.uuid, uuid]}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return dataList
}
